define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'orderstore/index' + location.search,
                    add_url: 'orderstore/add',
                    edit_url: '',
                    del_url: '',
                    multi_url: 'orderstore/multi',
                    import_url: 'orderstore/import',
                    table: 'orderstore',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'createtime',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'station_name', title: __('门店名称'), operate: false},
                        {field: 'user_id', title: __('用户id')},
                        {field: 'order_no', title: __('订单号'), operate: 'LIKE'},
                        {field: 'total_price', title: __('总价'), operate:'BETWEEN'},
                        {field: 'total_pay_price', title: __('总支付金额 '), operate:'BETWEEN'},
                        {field: 'is_pay', title: __('付款状态'), searchList: {"0":__('未支付'),"2":__('已支付')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_type', title: __('支付类型'), searchList: {"1":__('微信'),"2":__('支付宝'),"3":__('云闪付'),"4":__('pos机'),"5":__('现金')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_time', title: __('支付时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('订单类型'), searchList: {"1":__('充值订单'),"2":__('油品订单'),"3":__('商品订单')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('订单状态'), searchList: {"0":__('交易'),"2":__('取消')}, formatter: Table.api.formatter.status},
                        {field: 'source_type', title: __('订单平台'), searchList: {"1":__('小程序'),"2":__('PC')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},


                        // {
                        //     field: 'operate',
                        //     title: __('Operate'),
                        //     table: table,
                        //     events: Table.api.events.operate,
                        //     formatter: Table.api.formatter.operate,
                        //     buttons: [
                        //         {
                        //             name: 'receivable',
                        //             text: '查看详情',
                        //             title: '查看详情',
                        //             classname: 'btn btn-xs btn-danger btn-dialog btn-receivable',
                        //             icon: 'fa fa-keyboard-o',
                        //             url: 'orderstore/show',
                        //             extend: 'data-area=\'["80%", "80%"]\'',
                        //             visible: function (row) {
                        //                 // 自定义按钮 动态是否显示
                        //                 if (row.status == -1) {
                        //                     return false;
                        //                 }
                        //                 return true;
                        //             }
                        //         }
                        //     ],
                        //
                        // }



                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
